<?php
    include '../common/database.php';
    $id_device=$_GET['iddevice'];
    $name_device=$_GET['namedevice'];
    $query = "SELECT * FROM user_tamquoc WHERE id_device=:id_device";
    $stm = $db->prepare($query);
    $stm->execute(array(':id_device' => $id_device));
    $row = $stm->rowCount();
    if ($row<1){
        $sql = "INSERT INTO user_tamquoc (id,id_device,name_device,date_login,date_create,count,state) VALUES ('','$id_device','$name_device',NOW(),NOW(),'1','1')";
        $db->exec($sql) or die('Loi truy van');
    }
    else{
        $query = "UPDATE user_tamquoc SET date_login=NOW(),count=count+1 WHERE id_device='$id_device'";
        $db->exec($query) or die('Loi truy van');
    }
    echo 'success';
?>